const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");

const resolve = (...uri) => path.join(process.cwd(), ...uri);

module.exports = [
  {
    entry: {
      //入口文件可以指定名字
      catalog: "./src/lib/catalog.js",
    },
    // disables uglify.
    optimization: {
      minimize: false, 
    },
    output: {
      //输出文件路径设置
      path: resolve("dist"),
      filename: "[name].js",
      // 这里填你要暴露到全局的名字
      library: "Catalog",
      libraryTarget: "umd",
      libraryExport: "default",
    },
    plugins: [
      new HtmlWebpackPlugin({
        // 输出点
        filename: resolve("dist", "index.html"),
        // 模板读取点
        template: resolve("public", "index.html"),
        // 注入位置 合法值 body head 或者布尔值
        inject: "body",
      }),
    ],
  },
  // lib和程序入口分开
  {
    entry: {
      main: "./src/main.js",
    },
    output: {
      path: resolve("dist"),
      filename: "[name].js",
    },
    optimization: {
      minimize: false, 
    },
    plugins: [
      new HtmlWebpackPlugin({
        filename: resolve("dist", "index.html"),
        // 只能在上一个lib构建完成的时候做 这样写了以后还不能直接webpack命令跑 必须要用代码(build.js)控制程序
        template: resolve("dist", "index.html"),
        inject: "body",
      }),
      new CopyWebpackPlugin([
        {
          from: resolve("public", "assets"),
          to: "assets",
        },
      ]),
    ],
  },
];
